/**
 * admui-basic v2.1.0 (http://www.admui.com/)
 * Copyright 2015-2019 Admui Team
 * Licensed under the Admui License 1.1 (http://www.admui.com/about/license)
 */
(function(window, document, $) {
  'use strict';

  window.App.extend({
    run: function() {
      $('#dataTableExample').DataTable(
        $.concatCpt('dataTable', {
          initComplete: function() {
            var api = this.api();
            api
              .columns()
              .indexes()
              .flatten()
              .each(function(i) {
                var column = api.column(i);
                var select = $(
                  '<select class="form-control"><option value="">--请选择--</option></select>'
                )
                  .appendTo($(column.footer()).empty())
                  .on('change', function() {
                    var val = $.fn.dataTable.util.escapeRegex($(this).val());
                    column.search(val ? '^' + val + '$' : '', true, false).draw();
                  });
                column
                  .data()
                  .unique()
                  .sort()
                  .each(function(d) {
                    select.append('<option value="' + d + '">' + d + '</option>');
                  });
              });
          }
        })
      );
    }
  });

  window.App.run();
})(window, document, jQuery);
